package com.ymatou.counter.api.testcase;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.counter.api.parameter.GetNaturalListBean;
import com.ymatou.counter.api.service.GetNaturalListCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;
import com.ymt.utils.tag.P3;
import com.ymttest.business.service.CounterCallService;
import com.ymttest.utils.TestDataManager;
import com.ymttest.utils.YMTDateUtil;
import com.ymttest.utils.constant.ECode;

/**
 * 获取指定时间段内计数器 FreeMaker Template自动生成代码
 */
@TestSuite
public class Ts_GetNaturalList {
	private static GetNaturalListBean getNaturalListBean;
	private static GetNaturalListCall getNaturalListCall;

	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("获取指定时间计数器");
	}

	@Before
	public void caseUp() {
		getNaturalListBean = new GetNaturalListBean();
		getNaturalListCall = new GetNaturalListCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(getNaturalListCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_GetNaturalList_001() {
		Logger.start(true,"获取指定时间计数器成功");
		try {
			String TargetId = TestDataManager.getRandomUUID().toString();
			int value = 2;
			Logger.comment("给TargetId为"+TargetId + ":添加计数器 c1:" + value);
			new CounterCallService().setNatural("Test", "nc1", TargetId, 1, value);
			getNaturalListBean.setAppId("Test");
			getNaturalListBean.setCounter("nc1");
			getNaturalListBean.setTargetId(TargetId);
			String StartTime = YMTDateUtil.getBeforeOrNextDay(-1);
			String EndTime = YMTDateUtil.getBeforeOrNextDay(1);
			getNaturalListBean.setStartTime(StartTime);
			getNaturalListBean.setEndTime(EndTime);
			getNaturalListCall.setData(getNaturalListBean);
			getNaturalListCall.callService();
			Logger.verifyEquals(ECode.SUCCESS, getNaturalListCall.getCode(), "验证CODE状态");
			Logger.verifyEquals(ECode.SUCCESSMSG3, getNaturalListCall.getMsg(), "验证Msg");
			Logger.verifyEquals(value,
					getNaturalListCall.getData().get(YMTDateUtil.getSysTime("yyyy-MM-dd'T'00:00:00")), "验证计数器的值");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_GetNaturalList_002() {
		Logger.start(false,"不输入AppId,失败");
		try {
			String TargetId = TestDataManager.getRandomUUID().toString();
			int value = 2;
			Logger.comment("给TargetId为"+TargetId + ":添加计数器 c1:" + value);
			new CounterCallService().setNatural("Test", "nc1", TargetId, 1, value);
			getNaturalListBean.setCounter("nc1");
			getNaturalListBean.setTargetId(TargetId);
			String StartTime = YMTDateUtil.getBeforeOrNextDay(-1);
			String EndTime = YMTDateUtil.getBeforeOrNextDay(1);
			getNaturalListBean.setStartTime(StartTime);
			getNaturalListBean.setEndTime(EndTime);
			getNaturalListCall.setData(getNaturalListBean);
			getNaturalListCall.callService();
			Logger.verifyEquals(ECode.ERROR400, getNaturalListCall.getCode(), "验证CODE状态");
			Logger.verifyEquals(ECode.NOAPPID_MSG, getNaturalListCall.getMsg(), "验证Msg");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_GetNaturalList_003() {
		Logger.start(false,"不输入TargetId,失败");
		try {
			String TargetId = TestDataManager.getRandomUUID().toString();
			int value = 2;
			Logger.comment("给TargetId为"+TargetId + ":添加计数器 c1:" + value);
			new CounterCallService().setNatural("Test", "nc1", TargetId, 1, value);
			getNaturalListBean.setAppId("Test");
			getNaturalListBean.setCounter("nc1");
			String StartTime = YMTDateUtil.getBeforeOrNextDay(-1);
			String EndTime = YMTDateUtil.getBeforeOrNextDay(1);
			getNaturalListBean.setStartTime(StartTime);
			getNaturalListBean.setEndTime(EndTime);
			getNaturalListCall.setData(getNaturalListBean);
			getNaturalListCall.callService();
			Logger.verifyEquals(ECode.ERROR400, getNaturalListCall.getCode(), "验证CODE状态");
			Logger.verifyEquals(ECode.NOTARGETID_MSG, getNaturalListCall.getMsg(), "验证Msg");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_GetNaturalList_004() {
		Logger.start(false,"不输入Counter,失败");
		try {
			String TargetId = TestDataManager.getRandomUUID().toString();
			int value = 2;
			Logger.comment("给TargetId为"+TargetId + ":添加计数器 c1:" + value);
			new CounterCallService().setNatural("Test", "nc1", TargetId, 1, value);
			getNaturalListBean.setAppId("Test");
			getNaturalListBean.setTargetId(TargetId);
			String StartTime = YMTDateUtil.getBeforeOrNextDay(-1);
			String EndTime = YMTDateUtil.getBeforeOrNextDay(1);
			getNaturalListBean.setStartTime(StartTime);
			getNaturalListBean.setEndTime(EndTime);
			getNaturalListCall.setData(getNaturalListBean);
			getNaturalListCall.callService();
			Logger.verifyEquals(ECode.ERROR400, getNaturalListCall.getCode(), "验证CODE状态");
			Logger.verifyEquals(ECode.NOCOUNTER_MSG, getNaturalListCall.getMsg(), "验证Msg");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P3.class)
	@TestCase
	@Ignore
	public void Tc_GetNaturalList_005() {
		Logger.start(false,"不输入开始时间，失败");
		try {
			String TargetId = TestDataManager.getRandomUUID().toString();
			int value = 2;
			Logger.comment("给TargetId为"+TargetId + ":添加计数器 c1:" + value);
			new CounterCallService().setNatural("Test", "nc1", TargetId, 1, value);
			getNaturalListBean.setAppId("Test");
			getNaturalListBean.setCounter("nc1");
			getNaturalListBean.setTargetId(TargetId);
			String EndTime = YMTDateUtil.getBeforeOrNextDay(1);
			getNaturalListBean.setEndTime(EndTime);
			getNaturalListCall.setData(getNaturalListBean);
			getNaturalListCall.callService();
			Logger.verifyEquals(ECode.ERROR400, getNaturalListCall.getCode(), "验证CODE状态");
			Logger.verifyEquals(ECode.NOTNULL_MSG, getNaturalListCall.getMsg(), "验证Msg");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P3.class)
	@TestCase
	@Ignore
	public void Tc_GetNaturalList_006() {
		Logger.start(false,"不输入结束时间，失败");
		try {
			String TargetId = TestDataManager.getRandomUUID().toString();
			int value = 2;
			Logger.comment("给TargetId为"+TargetId + ":添加计数器 c1:" + value);
			new CounterCallService().setNatural("Test", "nc1", TargetId, 1, value);
			getNaturalListBean.setAppId("Test");
			getNaturalListBean.setCounter("nc1");
			getNaturalListBean.setTargetId(TargetId);
			String StartTime = YMTDateUtil.getBeforeOrNextDay(-1);
			getNaturalListBean.setStartTime(StartTime);
			getNaturalListCall.setData(getNaturalListBean);
			getNaturalListCall.callService();
			Logger.verifyEquals(ECode.ERROR400, getNaturalListCall.getCode(), "验证CODE状态");
			Logger.verifyEquals(ECode.NOTNULL_MSG, getNaturalListCall.getMsg(), "验证Msg");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_GetNaturalList_007() {
		Logger.start(false, "输入错误的AppId,失败");
		try {
			String TargetId = TestDataManager.getRandomUUID().toString();
			int value = 2;
			Logger.comment("给TargetId为"+TargetId + ":添加计数器 c1:" + value);
			new CounterCallService().setNatural("Test", "nc1", TargetId, 1, value);
			getNaturalListBean.setAppId("errTest");
			getNaturalListBean.setCounter("nc1");
			getNaturalListBean.setTargetId(TargetId);
			String StartTime = YMTDateUtil.getBeforeOrNextDay(-1);
			String EndTime = YMTDateUtil.getBeforeOrNextDay(1);
			getNaturalListBean.setStartTime(StartTime);
			getNaturalListBean.setEndTime(EndTime);
			getNaturalListCall.setData(getNaturalListBean);
			getNaturalListCall.callService();
			Logger.verifyEquals(ECode.ERROR500, getNaturalListCall.getCode(), "验证CODE状态");
			Logger.verifyEquals(ECode.NONATURALNODE_MSG, getNaturalListCall.getMsg(), "验证Msg");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_GetNaturalList_008() {
		Logger.start(false, "输入错误的Counter,失败");
		try {
			String TargetId = TestDataManager.getRandomUUID().toString();
			int value = 2;
			Logger.comment("给TargetId为"+TargetId + ":添加计数器 c1:" + value);
			new CounterCallService().setNatural("Test", "nc1", TargetId, 1, value);
			getNaturalListBean.setAppId("Test");
			getNaturalListBean.setCounter("errorc1");
			getNaturalListBean.setTargetId(TargetId);
			String StartTime = YMTDateUtil.getBeforeOrNextDay(-1);
			String EndTime = YMTDateUtil.getBeforeOrNextDay(1);
			getNaturalListBean.setStartTime(StartTime);
			getNaturalListBean.setEndTime(EndTime);
			getNaturalListCall.setData(getNaturalListBean);
			getNaturalListCall.callService();
			Logger.verifyEquals(ECode.ERROR500, getNaturalListCall.getCode(), "验证CODE状态");
			Logger.verifyEquals(ECode.NONATURALNODE_MSG, getNaturalListCall.getMsg(), "验证Msg");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_GetNaturalList_009() {
		Logger.start(false, "输入不存在的TargetId,没有查询出数据");
		try {
			String TargetId = TestDataManager.getRandomUUID().toString();
			int value = 2;
			Logger.comment("给TargetId为"+TargetId + ":添加计数器 c1:" + value);
			new CounterCallService().setNatural("Test", "nc1", TargetId, 1, value);
			getNaturalListBean.setAppId("Test");
			getNaturalListBean.setCounter("errorc1");
			String TargetId2 = TestDataManager.getRandomUUID().toString();
			getNaturalListBean.setTargetId(TargetId2);
			String StartTime = YMTDateUtil.getBeforeOrNextDay(-1);
			String EndTime = YMTDateUtil.getBeforeOrNextDay(1);
			getNaturalListBean.setStartTime(StartTime);
			getNaturalListBean.setEndTime(EndTime);
			getNaturalListCall.setData(getNaturalListBean);
			getNaturalListCall.callService();
			Logger.verifyEquals(ECode.ERROR500, getNaturalListCall.getCode(), "验证CODE状态");
			Logger.verifyEquals(ECode.NONATURALNODE_MSG, getNaturalListCall.getMsg(), "验证Msg");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P3.class)
	@TestCase
	@Ignore
	public void Tc_GetNaturalList_010() {
		Logger.start(false,"开始时间格式错误");
		try {
			String TargetId = TestDataManager.getRandomUUID().toString();
			int value = 2;
			Logger.comment("给TargetId为"+TargetId + ":添加计数器 c1:" + value);
			new CounterCallService().setNatural("Test", "nc1", TargetId, 1, value);
			getNaturalListBean.setAppId("Test");
			getNaturalListBean.setCounter("nc1");
			getNaturalListBean.setTargetId(TargetId);
			String StartTime = "aabbcc";
			String EndTime = YMTDateUtil.getBeforeOrNextDay(1);
			getNaturalListBean.setStartTime(StartTime);
			getNaturalListBean.setEndTime(EndTime);
			getNaturalListCall.setData(getNaturalListBean);
			getNaturalListCall.callService();
			Logger.verifyEquals(ECode.ERROR400, getNaturalListCall.getCode(), "验证CODE状态");
			Logger.verifyEquals(ECode.NONATURALNODE_MSG, getNaturalListCall.getMsg(), "验证Msg");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P3.class)
	@TestCase
	@Ignore
	public void Tc_GetNaturalList_011() {
		Logger.start(false,"结束时间格式错误");
		try {
			String TargetId = TestDataManager.getRandomUUID().toString();
			int value = 2;
			Logger.comment("给TargetId为"+TargetId + ":添加计数器 c1:" + value);
			new CounterCallService().setNatural("Test", "nc1", TargetId, 1, value);
			getNaturalListBean.setAppId("Test");
			getNaturalListBean.setCounter("nc1");
			getNaturalListBean.setTargetId(TargetId);
			String StartTime = YMTDateUtil.getBeforeOrNextDay(-1);
			String EndTime = "aabbcc";
			getNaturalListBean.setStartTime(StartTime);
			getNaturalListBean.setEndTime(EndTime);
			getNaturalListCall.setData(getNaturalListBean);
			getNaturalListCall.callService();
			Logger.verifyEquals(ECode.ERROR400, getNaturalListCall.getCode(), "验证CODE状态");
			Logger.verifyEquals(ECode.NOTNULL_MSG, getNaturalListCall.getMsg(), "验证Msg");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P3.class)
	@TestCase
	@Ignore
	public void Tc_GetNaturalList_012() {
		Logger.start(false,"开始时间先于结束时间");
		try {
			String TargetId = TestDataManager.getRandomUUID().toString();
			int value = 2;
			Logger.comment("给TargetId为"+TargetId + ":添加计数器 c1:" + value);
			new CounterCallService().setNatural("Test", "nc1", TargetId, 1, value);
			getNaturalListBean.setAppId("Test");
			getNaturalListBean.setCounter("nc1");
			getNaturalListBean.setTargetId(TargetId);
			String EndTime = YMTDateUtil.getBeforeOrNextDay(-1);
			String StartTime = YMTDateUtil.getBeforeOrNextDay(1);
			getNaturalListBean.setStartTime(StartTime);
			getNaturalListBean.setEndTime(EndTime);
			getNaturalListCall.setData(getNaturalListBean);
			getNaturalListCall.callService();
			Logger.comment("发送getNaturalListCall报文:" + getNaturalListCall.getEntityString());
			Logger.comment("返回getNaturalListCall报文：" + getNaturalListCall.getReturnData());
			Logger.verifyEquals(ECode.ERROR400, getNaturalListCall.getCode(), "验证CODE状态");
			Logger.verifyEquals(ECode.NOTNULL_MSG, getNaturalListCall.getMsg(), "验证Msg");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}